// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import LData from "./LData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SoundManager
 {

    public static sounds:any={};

    public static playSound(name)
    {
        if(LData.yx==false)
        {
            return;
        }

        cc.resources.load("sound/"+name, cc.AudioClip, null, (err, clip:cc.AudioClip) => {
                
            if(clip!=null)
            {
                this.sounds[name]=clip;

                cc.audioEngine.playEffect(clip, false);
            }
           
        });
    }


    private static bgm_name="bgm";

    public static playBgm()
    {

        if(LData.yy==false)
        {
            return;
        }


        cc.resources.load("sound/"+this.bgm_name, cc.AudioClip, null, (err, clip:cc.AudioClip) => {
                
            console.log("clip==>"+clip)


            if(clip!=null)
            {
                this.sounds[this.bgm_name]=clip;

                cc.audioEngine.playMusic(clip, true);
            }
           
        });
    }
    public static stopBgm()
    {
        cc.audioEngine.stopMusic();
    }

}
